import { ApiProperty } from '@midwayjs/swagger'
import { Rule, RuleType } from '@midwayjs/validate'
import { BaseError } from '../../../common/base.error'
// import { stringValidate } from '../../../common/common.validate.rules'

export class UserDTO {

  @ApiProperty({ description: '用户ID' })
  @Rule(RuleType.allow(null))
  id?: string

  @ApiProperty({ description: '用户名' })
  @Rule(RuleType.string().max(13).required().error(new Error('用户名不能为空且不超过13位')))
  username: string

  @ApiProperty({ description: '密码' })
  @Rule(RuleType.string().required().error(new Error('密码不能为空')))
  password: string

  @ApiProperty({ description: '头像' })
  @Rule(RuleType.allow(null))
  avatar?: string

  @ApiProperty({ description: '角色' })
  @Rule(RuleType.allow(null).default(''))
  role?: string

  @ApiProperty({ description: '昵称' })
  nickname?: string

  @ApiProperty({ description: '联系方式' })
  phone?: string

  @ApiProperty({ description: '门店关联' })
  store?: any

  @ApiProperty({ description: '创建时间' })
  @Rule(RuleType.allow(null))
  create_date?: Date

  @ApiProperty({ description: '更新时间' })
  @Rule(RuleType.allow(null))
  update_date?: Date

}

export class LoginUserDTO {
  @ApiProperty({ description: '用户名' })
  @Rule(RuleType.string().min(4).max(13).error(new Error('用户名不能为空且不超过13位')))
  username: string

  @ApiProperty({ description: '密码' })
  @Rule(RuleType.string().min(6).max(13).error(new Error('密码不能为空且不超过13位')))
  password: string
}

export class UpdateUserDTO {
  @ApiProperty({ description: '用户ID' })
  @Rule(RuleType.allow(null))
  id?: string

  @ApiProperty({ description: '头像' })
  @Rule(RuleType.allow(null))
  avatar?: string

  @ApiProperty({ description: '昵称' })
  @Rule(RuleType.allow(null))
  nickname?: string

  @ApiProperty({ description: '联系方式' })
  @Rule(RuleType.allow(null))
  phone?: string

  @ApiProperty({ description: '角色' })
  @Rule(RuleType.allow(null))
  role?: string
}

export class UploadPwdDTO {
  @ApiProperty({ description: '密码' })
  @Rule(RuleType.string().error(BaseError.validateError('密码不能为空!')))
  password: string

  @ApiProperty({ description: '新密码' })
  @Rule(RuleType.string())
  newPassword: string

  @ApiProperty({ description: '确认密码' })
  @Rule(RuleType.string())
  reNewPassword: string
}

export class BindStoreDTO {
  @ApiProperty({ description: '用户ID' })
  id: string

  @ApiProperty({ description: '门店ID' })
  @Rule(RuleType.string().error(BaseError.validateError('门店ID不能为空!')))
  storeId: string
}
